//
//  NSString+ThumbnailImage.m
//  chengshiquan
//
//  Created by 任辰东 on 17/7/7.
//  Copyright © 2017年 任辰东. All rights reserved.
//

#import "NSString+ThumbnailImage.h"
#import <AVFoundation/AVFoundation.h>

@implementation NSString (ThumbnailImage)

- (UIImage*) thumbnailImageForVideo
{
    
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:self] options:nil];
    
    AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    
    gen.appliesPreferredTrackTransform = YES;
    
    CMTime time = CMTimeMakeWithSeconds(2.0, 600);
    
    NSError *error = nil;
    
    CMTime actualTime;
    
    CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
    
    UIImage *thumbImg = [[UIImage alloc] initWithCGImage:image];
    
    return thumbImg;
    
}

@end
